package com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.dto.Table01474Dto;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.dto.SaveTable01474FormDataDto;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.vo.Table01474FormDataVo;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.vo.Table01474ListVo;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.dto.Table01474ListDto;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.vo.Table18607Vo;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.entity.Table18607;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.dto.Table18607Dto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.entity.Table01474;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.vo.Table01474Vo;
import com.xjrsoft.module.customerTwo.companyManage.calculationExampleForm.service.ITable01474Service;

/**
 *  控制器
 *
 * @author pp
 * @since 2022-08-25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/calculationexampleform")
@Api(value = "CalculationExampleForm", tags = "CalculationExampleForm接口")
public class Table01474Controller {


	private final ITable01474Service table01474Service;


	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入table01474")
	@SaCheckPermission("calculationexampleform:view")
	public Response<Table01474FormDataVo> getFormData(@PathVariable String id) {
		Table01474FormDataVo formDataVo = new Table01474FormDataVo();
		// 主表数据
		Table01474 table01474 = table01474Service.getById(id);
		formDataVo.setTable01474Vo(BeanUtil.copy(table01474, Table01474Vo.class));
		// 从表数据
		formDataVo.setTable18607VoList(BeanUtil.copyList(table01474Service.getTable18607ByParentId(id), Table18607Vo.class));
		return Response.ok(formDataVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入table01474")
	@SaCheckPermission("calculationexampleform:view")
	public Response<PageOutput<Table01474ListVo>> getPageList(Table01474ListDto listDto) {
		IPage<Table01474> page = table01474Service.getPageList(listDto);
		List<Table01474ListVo> records = BeanUtil.copyList(page.getRecords(), Table01474ListVo.class);
		// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入table01474")
	@SaCheckPermission("calculationexampleform:add")
	public Response save(@RequestBody SaveTable01474FormDataDto formDto) {
		Table01474Dto table01474Dto = formDto.getTable01474Dto();
		Table01474 table01474 = BeanUtil.copy(table01474Dto, Table01474.class);
		List<Table18607Dto> table18607DtoList = formDto.getTable18607Dto();
		List<Table18607> table18607List = BeanUtil.copyList(table18607DtoList, Table18607.class);
		String dataId = table01474Service.addTable01474(table01474, table18607List);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入table01474")
	@SaCheckPermission("calculationexampleform:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTable01474FormDataDto formDto) {
		Table01474Dto table01474Dto = formDto.getTable01474Dto();
		Table01474 table01474 = BeanUtil.copy(table01474Dto, Table01474.class);

		List<Table18607Dto> table18607DtoList = formDto.getTable18607Dto();
		List<Table18607> table18607List = BeanUtil.copyList(table18607DtoList, Table18607.class);
		return Response.status(table01474Service.updateTable01474(id, table01474, table18607List));
	}


	
	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission("calculationexampleform:batchDelete")
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(table01474Service.delete(ids));
	}

	
}
